# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
from .items import XiaoYuGetDetail
from .constant import REDIS_CONNECT_SETURL,DB_MONGO_CONNECT_DB  #储存RUL网址
class XiaoyuwangPipeline(object):
    def __init__(self):
        print(1)
        print(1)
    def process_item(self, item, spider):
        if isinstance(item,XiaoYuGetDetail):
            db=DB_MONGO_CONNECT_DB['XiaoYu']['one']
            updateDict={
                'id':item['id']
            }
            print(item['id'])
            db.update(updateDict,item,upsert=True)
        else:
            for url in item['urls']:
                REDIS_CONNECT_SETURL.lpush('XiaoYu:url',url)
        # return item
        return 'success'